package com.balabala.gym_goods.controller.app;

import com.balabala.api.VipCardFeignClient;
import com.balabala.dto.VipCardDto;
import com.balabala.gym_goods.pojo.dto.AddAppointmentDto;
import com.balabala.gym_goods.pojo.entity.Course;
import com.balabala.gym_goods.pojo.entity.Evaluation;
import com.balabala.gym_goods.pojo.vo.CoachScheduleVo;
import com.balabala.gym_goods.service.CoachScheduleService;
import com.balabala.gym_goods.service.CourseService;
import com.balabala.gym_goods.service.EvaluationService;
import com.balabala.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:zl
 * Date:2023/5/7 20:07
 */
@Slf4j
@RestController
@CrossOrigin
@Api(tags = "小程序私教接口")
@RequestMapping("/app/coachSch")
public class CoachSchController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private CoachScheduleService coachScheduleService;
    @Autowired
    private VipCardFeignClient vipCardFeignClient;
    @Autowired
    private EvaluationService evaluationService;

    @ApiOperation(value = "查询当前私教课可预约时间段")
    @GetMapping(value = "/findAllTimeById")
    public Result findAll(@RequestParam Long id) {
        List<Integer> allTimeById = coachScheduleService.findAllTimeById(id);
        return Result.ok(allTimeById);
    }

    @ApiOperation(value = "查询可用会员卡")
    @GetMapping(value = "/findVipCardById")
    public Result findVipCardById(@RequestParam Long id) {
        //调用查询可用会员卡feign接口
        Result<List<VipCardDto>> supportVipCardByCourseId = vipCardFeignClient.getSupportVipCardByCourseId(id);
        return Result.ok(supportVipCardByCourseId.getData());
    }

    @GetMapping(value = "/findEvaluationByCoachSchId")
    @ApiOperation(value = "根据私教课id查询评价")
    public Result findEvaluationByCoachSchId(@RequestParam Long coachId) {

        List<Evaluation> evaluationBySpuId = evaluationService.findEvaluationByCoachSchId(coachId);

        return Result.ok(evaluationBySpuId);
    }

    @PostMapping(value = "/addAppointment")
    @ApiOperation(value = "根据用户id,添加预约时间段，预约人数，备注")
    public Result addAppointment(@RequestBody AddAppointmentDto addAppointmentDto) {
        return courseService.addAppointment(addAppointmentDto);

    }

    @GetMapping(value = "/findAllCoachSchedule")
    @ApiOperation(value = "根据场馆,查询所有私教课")
    public Result findAllCoachSch(@RequestParam Long id) {
        CoachScheduleVo allCoachSch = courseService.findAllCoachSch(id);
        return Result.ok(allCoachSch);
    }

}
